package com.yunji.framework_template.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yunji.framework_template.biz.service.NewsCommentsService;
import com.yunji.framework_template.common.web.Page;
import com.yunji.framework_template.common.web.Result;
import com.yunji.framework_template.orm.persistence.model.NewsComments;

/**
 * Created by fenglibin on 2018/11/26.
 */
@Controller
@RequestMapping("/newsComments/")
public class NewsCommentsController {

    @Autowired
    NewsCommentsService newsCommentsService;

    @RequestMapping("selectAll")
    @ResponseBody
    public Result<List<NewsComments>> selectAll() {
        return Result.success(newsCommentsService.selectAll());
    }

    @RequestMapping("select")
    @ResponseBody
    public Result<NewsComments> selectByPrimaryKey(Integer id) {
        return Result.success(newsCommentsService.selectByPrimaryKey(id));
    }

    @RequestMapping("selectByCondition")
    @ResponseBody
    public Result<List<NewsComments>> selectByCondition(NewsComments record) {
        return Result.success(newsCommentsService.selectByCondition(record));
    }

    @RequestMapping("count")
    @ResponseBody
    public Result<Integer> count(NewsComments record) {
        return Result.success(newsCommentsService.count(record));
    }

    @RequestMapping("insert")
    @ResponseBody
    public Result<Integer> insertSelective(NewsComments record) {
        return Result.success(newsCommentsService.insertSelective(record));
    }

    @RequestMapping("update")
    @ResponseBody
    public Result<Integer> updateByPrimaryKeySelective(NewsComments record) {
        return Result.success(newsCommentsService.updateByPrimaryKeySelective(record));
    }

    @RequestMapping("selectByPage")
    @ResponseBody
    public Result<Page<List<NewsComments>>> selectByPage(Page<NewsComments> page) {
        List<NewsComments> list = null;
        page = page.sequentialDisplayCalculate(newsCommentsService.count(page.getObj()));
        if (page.getTotalCount() > 0) {
            list = newsCommentsService.selectByPage(page);
        }
        Page<List<NewsComments>> result = new Page<List<NewsComments>>(page, list);
        return Result.success(result);
    }

    @RequestMapping("deleteByCondition1")
    @ResponseBody
    public Result<Integer> deleteByCondition(NewsComments record) {
        return Result.success(newsCommentsService.deleteByCondition(record));
    }

    @RequestMapping("delete1")
    @ResponseBody
    public Result<Integer> deleteByPrimaryKey(Integer id) {
        return Result.success(newsCommentsService.deleteByPrimaryKey(id));
    }

}
